use std::collections::HashMap;

use derive_builder::Builder;
use serde::{Deserialize, Serialize};

use crate::error::Error;

#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
pub enum DatabaseType {
    #[default]
    #[serde(rename = "mysql")]
    MySQL,
    #[serde(rename = "sqlite")]
    SQLite,
    #[serde(rename = "dgraph")]
    Dgraph,
}

#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
pub enum ConnectorProtocol {
    #[default]
    #[serde(rename = "mysql")]
    MySQL,
    #[serde(rename = "sqlite")]
    SQLite,
    #[serde(rename = "jdbc")]
    Jdbc,
    #[serde(rename = "dgraph")]
    Dgraph,
}

#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
#[builder(name = "DataSourceBuilder")]
#[builder(pattern = "mutable")]
#[builder(setter(into, strip_option), default)]
#[builder(derive(Debug))]
#[builder(build_fn(error = "Error"))]
pub struct DataSource {
    pub id: u32,
    pub database_type: DatabaseType,
    pub protocol: ConnectorProtocol,
    pub url: String,
    pub username: Option<String>,
    pub password: Option<String>,
    pub options: Option<HashMap<String, String>>,
}
